package com.hn.zhijian.utils;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author carl chen
 */
public class DateUUIDUtil {
	public static final String Y_M_D_ZH = "yyyy年MM月dd日";
	public static final String Y_M_D = "yyyy-MM-dd";
	public static final String Y_M = "yyyy-MM";
	public static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";
	public static final String YYYYMMDDHHMMSS =  "yyyyMMddHHmmss";
	public static final String YYYYMMDDHH = "yyyyMMdd";
	/**
	 * 小时
	 */
	public static final String HH_MM_SS = "HH:mm:ss";

	public static Timestamp string2Timestamp(String dateValue) {
		if (dateValue != null && dateValue.trim().length() > 0) {
			return Timestamp.valueOf(dateValue);
		}
		return null;
	}

	public static Timestamp getCurrentTimeTimestamp() {
		return new Timestamp(System.currentTimeMillis());
	}

	public static String getCurrentTime() {
		SimpleDateFormat f = new SimpleDateFormat(DEFAULT_FORMAT);
		Date date = new Date();
		return f.format(date);
	}


	public static String getCurrentTime(String format) {
		SimpleDateFormat f = new SimpleDateFormat(format);
		Date date = new Date();
		return f.format(date);
	}

	public static String data(String data){
		SimpleDateFormat f = new SimpleDateFormat(data);
		Date date = new Date();

		return f.format(date);
	}

	/**
	 *
	 * @return
	 */
	public static String getSpecifiedData(String data,int time){
		SimpleDateFormat f = new SimpleDateFormat(data);
		Date date = new Date();

		date.setMinutes(date.getMinutes() + time);

		return f.format(date);
	}

	public static String getDateUUid(){
		SimpleDateFormat formatter = new SimpleDateFormat(YYYYMMDDHHMMSS);
		return formatter.format(new Date());
	}

	public static void main(String[] args) {
		System.out.println(getSpecifiedData("yyyyMMddHHmmss",10));
	}


	public static String formatDate(String date, String pattern) {
		SimpleDateFormat f = new SimpleDateFormat(pattern);
		return f.format(date);
	}

	public static String timestamp2ZHstring(Timestamp timestamp) {
		if(timestamp!=null){
			SimpleDateFormat f = new SimpleDateFormat(YYYYMMDDHHMMSS);
			try {
				Date d = f.parse(timestamp.toString());
				f = new SimpleDateFormat("yyyy年MM月dd日");
				return f.format(d);
			} catch (ParseException e1) {
				e1.printStackTrace();
			}
		}
		return "";
	}


	public static String timestamp2ZHstring(Timestamp timestamp,String format) {
		if(timestamp!=null){
			SimpleDateFormat f = new SimpleDateFormat(format);

//				Date d = f.parse(timestamp.toString());
//				f = new SimpleDateFormat("yyyy年MM月dd日");
				return f.format(timestamp);

		}
		return "";
	}

}
